package com.zboin.filemger.controller;

import com.zboin.filemger.service.FileManageService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author zhboom
 * @date 2025/7/10 22:37
 */
@RestController
public class FileManageController {

    private final FileManageService fileManageService;

    public FileManageController(FileManageService fileManageService) {
        this.fileManageService = fileManageService;
    }

    @PostMapping("/upload-chunk")
    public ResponseEntity<String> uploadChunk(
            @RequestParam("file") MultipartFile file,
            @RequestParam("chunkIndex") int chunkIndex,
            @RequestParam("fileMd5") String fileMd5,
            @RequestParam("fileName") String fileName
    ) {
        return fileManageService.uploadChunk(file, chunkIndex, fileMd5, fileName);
    }

    @PostMapping("/merge-chunks")
    public ResponseEntity<String> mergeChunks(
            @RequestParam("fileMd5") String fileMd5,
            @RequestParam("fileName") String fileName
    ) {
        return fileManageService.mergeChunks(fileMd5, fileName);
    }

    @GetMapping("/upload-status")
    public ResponseEntity<List<Integer>> uploadStatus(
            @RequestParam("fileMd5") String fileMd5
    ) {
        return fileManageService.uploadStatus(fileMd5);
    }
}
